﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Roton.Engine.Structures
{
    abstract class Element : IElement
    {
        public ElementMemoryMap Memory { get; private set; }

        public Element(ElementMemoryMap memory)
        {
            this.Memory = memory;
        }   

        [
        Category("Environment"),
        DisplayName("Action Code"),
        ReadOnly(true),
        TypeConverter(typeof(Int32Converter)),
        ]
        public int ActionCode
        {
            get { return Memory.ActionCode.Read(); }
            set { Memory.ActionCode.Write(value); }
        }

        [
        Category("Editor"),
        DisplayName("Edit Board"),
        ReadOnly(true),
        TypeConverter(typeof(StringConverter)),
        ]
        public string Board
        {
            get { return Memory.Board.Read(); }
            set { Memory.Board.Write(value); }
        }

        [
        Category("Editor"),
        DisplayName("Category"),
        ReadOnly(true),
        TypeConverter(typeof(StringConverter)),
        ]
        public string Category
        {
            get { return Memory.Category.Read(); }
            set { Memory.Category.Write(value); }
        }

        [
        Category("Appearance"),
        DisplayName("Character"),
        ReadOnly(true),
        TypeConverter(typeof(ByteConverter)),
        ]
        public int Char
        {
            get { return Memory.Char.Read(); }
            set { Memory.Char.Write(value.ToByte()); }
        }

        [
        Category("Environment"),
        DisplayName("Draw Code"),
        ReadOnly(true),
        TypeConverter(typeof(Int32Converter)),
        ]
        public int CharCode
        {
            get { return Memory.CharCode.Read(); }
            set { Memory.CharCode.Write(value); }
        }

        [
        Category("Editor"),
        DisplayName("Edit Code"),
        ReadOnly(true),
        TypeConverter(typeof(StringConverter)),
        ]
        public string Code
        {
            get { return Memory.Code.Read(); }
            set { Memory.Code.Write(value); }
        }

        [
        Category("Appearance"),
        DisplayName("Color"),
        ReadOnly(true),
        TypeConverter(typeof(ByteConverter)),
        ]
        public int Color
        {
            get { return Memory.Color.Read(); }
            set { Memory.Color.Write(value.ToByte()); }
        }

        [
        Category("Behavior"),
        DisplayName("Default Cycle"),
        ReadOnly(true),
        TypeConverter(typeof(Int16Converter)),
        ]
        public int Cycle
        {
            get { return Memory.Cycle.Read(); }
            set { Memory.Cycle.Write(value.ToInt16()); }
        }

        [
        Category("Behavior"),
        DisplayName("Destructible"),
        ReadOnly(true),
        TypeConverter(typeof(ByteConverter)),
        ]
        public int Destructible
        {
            get { return Memory.Destructible.Read(); }
            set { Memory.Destructible.Write(value.ToByte()); }
        }

        [
        Category("Behavior"),
        DisplayName("Floor In Editor"),
        ReadOnly(true),
        TypeConverter(typeof(ByteConverter)),
        ]
        public int EditorFloor
        {
            get { return Memory.EditorFloor.Read(); }
            set { Memory.EditorFloor.Write(value.ToByte()); }
        }

        [
        Category("Behavior"),
        DisplayName("Floor"),
        ReadOnly(true),
        TypeConverter(typeof(ByteConverter)),
        ]
        public int Floor
        {
            get { return Memory.Floor.Read(); }
            set { Memory.Floor.Write(value.ToByte()); }
        }

        [
        Category("Environment"),
        DisplayName("Interaction Code"),
        ReadOnly(true),
        TypeConverter(typeof(Int32Converter)),
        ]
        public int InteractionCode
        {
            get { return Memory.InteractionCode.Read(); }
            set { Memory.InteractionCode.Write(value); }
        }

        [
        Category("Editor"),
        DisplayName("Editor Key"),
        ReadOnly(true),
        TypeConverter(typeof(ByteConverter)),
        ]
        public int Key
        {
            get { return Memory.Key.Read(); }
            set { Memory.Key.Write(value.ToByte()); }
        }

        [
        Category("Editor"),
        DisplayName("Editor Menu"),
        ReadOnly(true),
        TypeConverter(typeof(Int16Converter)),
        ]
        public int Menu
        {
            get { return Memory.Menu.Read(); }
            set { Memory.Menu.Write(value.ToByte()); }
        }

        [
        Category("Environment"),
        DisplayName("Name"),
        ReadOnly(true),
        TypeConverter(typeof(StringConverter)),
        ]
        public string Name
        {
            get { return Memory.Name.Read(); }
            set { Memory.Name.Write(value); }
        }

        [
        Category("Environment"),
        DisplayName("Edit Parameter 1"),
        ReadOnly(true),
        TypeConverter(typeof(StringConverter)),
        ]
        public string P1
        {
            get { return Memory.P1.Read(); }
            set { Memory.P1.Write(value); }
        }

        [
        Category("Environment"),
        DisplayName("Edit Parameter 2"),
        ReadOnly(true),
        TypeConverter(typeof(StringConverter)),
        ]
        public string P2
        {
            get { return Memory.P2.Read(); }
            set { Memory.P2.Write(value); }
        }

        [
        Category("Environment"),
        DisplayName("Edit Parameter 3"),
        ReadOnly(true),
        TypeConverter(typeof(StringConverter)),
        ]
        public string P3
        {
            get { return Memory.P3.Read(); }
            set { Memory.P3.Write(value); }
        }

        [
        Category("Behavior"),
        DisplayName("Points"),
        ReadOnly(true),
        TypeConverter(typeof(Int16Converter)),
        ]
        public int Points
        {
            get { return Memory.Points.Read(); }
            set { Memory.Points.Write(value.ToInt16()); }
        }

        [
        Category("Behavior"),
        DisplayName("Pushable"),
        ReadOnly(true),
        TypeConverter(typeof(ByteConverter)),
        ]
        public int Pushable
        {
            get { return Memory.Pushable.Read(); }
            set { Memory.Pushable.Write(value.ToByte()); }
        }

        [
        Category("Appearance"),
        DisplayName("Always Show"),
        ReadOnly(true),
        TypeConverter(typeof(ByteConverter)),
        ]
        public int Show
        {
            get { return Memory.Show.Read(); }
            set { Memory.Show.Write(value.ToByte()); }
        }

        [
        Category("Editor"),
        DisplayName("Edit Step"),
        ReadOnly(true),
        TypeConverter(typeof(StringConverter)),
        ]
        public string Step
        {
            get { return Memory.Step.Read(); }
            set { Memory.Step.Write(value); }
        }
    }
}
